package chi_example_java;

import java.util.Enumeration;
import java.util.Vector;

public class Customer {
	
	private Vector<Rental> _rentals = new Vector<Rental>();
	private String _name;
	
	public Customer(String name){
		_name = name;
	}


	public String getName() {
		return _name;
	}
	
	public void addRental(Rental rental) {
		_rentals.addElement(rental);
		
	}
	
	public String statement() {
		double totalAmount = 0;
		int frequentRenderPoints = 0;
		String result = "Rental record for " + getName() + "\n";
		Enumeration<Rental> rentals = _rentals.elements();
		while (rentals.hasMoreElements())
		{
			double thisAmount = 0;
			Rental each = (Rental) rentals.nextElement();
			switch(each.getMovie().getPriceCode())
			{
			case Movie.REGULAR:
				thisAmount += 2;
				if(each.getDaysRented() > 2)
				{
					thisAmount += (each.getDaysRented() - 2) * 1.5;
				}
				break;
			case Movie.NEW_RELEASE:
				thisAmount += each.getDaysRented() * 3;
				break;
			case Movie.CHILDREN:
				thisAmount += 1.5;
				if (each.getDaysRented() > 3)
				{
					thisAmount += (each.getDaysRented() - 3) * 1.5;
				}
				break;

			}

			frequentRenderPoints ++;
			if(each.getMovie().getPriceCode() == Movie.NEW_RELEASE &&
					each.getDaysRented() > 1)
			{
				frequentRenderPoints ++;
			}

			result += "\t" + each.getMovie().getTitle() + "\t" + Double.toString(thisAmount) + "\n";
			totalAmount += thisAmount;
		}

		result += "Amount owned is " + Double.toString(totalAmount) + "\n";
		result += "You earned " + Integer.toString(frequentRenderPoints) + " frequent renter points";
		return result;
	}
}
